package view.listeners;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import controller.Controller;

import view.GuiBuilder;
import view.components.IpAddressTable;
import view.components.NetworkTree;
import view.views.StartUpViewPanel;

/**
 * @author Alexander Müller
 * 
 */
public class DeleteListener implements ActionListener {

	private final Window comp;
	

	public DeleteListener(Window comp) {
		this.comp = comp;
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		StartUpViewPanel panel = (StartUpViewPanel) Controller.getInstance().getGuiBuilder().getContentViewPanel();
		NetworkTree tree = panel.getNetworkTree();
		IpAddressTable table = panel.getIpAdressTable();
		if (tree.getSelectedNode() != null && table.getSelectedRow() == -1) {
			tree.removeRow();
		}
		if (tree.getSelectedNode() != null && table.getSelectedRow() != -1) {
			table.setIpAddressEmpty(table.getSelectedIPAdress());
		}
		comp.dispose();
	}

}